# 触发变换按钮样式

from PyQt5.Qt import QLabel, QPixmap


class AddBtnCss(QLabel):
    def __init__(self, btn='normal', func=None, parent=None):
        '''
        :param btn: 按钮标签
        :param func: 按钮的功能
        :param parent: 父类框
        '''
        super(AddBtnCss, self).__init__(parent)

        self.btn = btn
        self.func = func
        self.parent = parent

        self.height = 1.0
        self.width = 1.0

        # 初始化按钮样式
        if self.btn == 'normal':
            self.setPixmap(QPixmap(':images/normal.png').scaled(int(self.width * 100), int(self.height * 100)))
        if self.btn == 'launch':
            self.setPixmap(QPixmap(':images/launch.png').scaled(int(self.width * 200), int(self.height * 200)))

    # 鼠标放到按钮上
    def enterEvent(self, *args, **kwargs):
        if self.btn == 'normal':
            self.setPixmap(QPixmap(':images/normal_1.png').scaled(int(self.width * 100), int(self.height * 100)))
        if self.btn == 'launch':
            self.setPixmap(QPixmap(':images/launch.png').scaled(int(self.width * 200), int(self.height * 200)))

    # 鼠标离开按钮
    def leaveEvent(self, *args, **kwargs):
        if self.btn == 'normal':
            self.setPixmap(QPixmap(':images/normal.png').scaled(int(self.width * 100), int(self.height * 100)))
        if self.btn == 'launch':
            self.setPixmap(QPixmap(':images/launch.png').scaled(int(self.width * 200), int(self.height * 200)))

    # 按钮点击触发事件
    def mousePressEvent(self, *args, **kwargs):
        self.func()
